<?php

/**
 * +----------------------------------------------------------------------
 * | 后台页面
 * +----------------------------------------------------------------------
 *                                            ...     .............
 *                                          ..   .:!o&*&&&&&ooooo&; .
 *                                        ..  .!*%*o!;.
 *                                      ..  !*%*!.      ...
 *                                     .  ;$$!.   .....
 *                          ........... .*#&   ...
 *                                     :$$: ...
 *                          .;;;;;;;:::#%      ...
 *                        . *@ooooo&&&#@***&&;.   .
 *                        . *@       .@%.::;&%$*!. . .
 *          ................!@;......$@:      :@@$.
 *                          .@!   ..!@&.:::::::*@@*.:..............
 *        . :!!!!!!!!!!ooooo&@$*%%%*#@&*&&&&&&&*@@$&&&oooooooooooo.
 *        . :!!!!!!!!;;!;;:::@#;::.;@*         *@@o
 *                           @$    &@!.....  .*@@&................
 *          ................:@* .  ##.     .o#@%;
 *                        . &@%..:;@$:;!o&*$#*;  ..
 *                        . ;@@#$$$@#**&o!;:   ..
 *                           :;:: !@;        ..
 *                               ;@*........
 *                       ....   !@* ..
 *                 ......    .!%$! ..     | AUTHOR: dfer
 *         ......        .;o*%*!  .       | EMAIL: df_business@qq.com
 *                .:;;o&***o;.   .        | QQ: 3504725309
 *        .;;!o&****&&o;:.    ..          | WEBSITE: http://www.dfer.site
 * +----------------------------------------------------------------------
 *
 */

namespace plugins\dfer_thinkcmf_tools\controller;

use plugins\dfer_thinkcmf_tools\model\OssUploadRecordModel;
use Dfer\Tools\Statics\{Common};
use Dfer\Tools\AliOss;

class AdminAssetController extends AdminBaseController
{
    /**
     * 删除文件     
     */
    public function delete()
    {
        if ($this->request->isPost()) {
            $id            = $this->request->param('id');
            $filePath = OssUploadRecordModel::where('id', $id)->value('file_path');
            // var_dump($id,$filePath);

            $access_id =  config('oss.access_id');
            $access_key =  config('oss.access_key');
            $bucket =  config('oss.bucket');
            $endpoint =  config('oss.endpoint');
            // 调试日志保存在`/data/logs/`
            $debug = 1;

            $oss = new AliOss(compact('access_id', 'access_key', 'bucket', 'endpoint', 'debug'));
            $res = $oss->delFileOss($filePath);
            // var_dump($res);
            if ($res) {
                OssUploadRecordModel::where('id', $id)->delete();
                $this->success(lang('DELETE_SUCCESS'));
            } else {
                $this->error(lang('DELETE_FAILED'));
            }
        }
    }
}
